package com.scgl.suppliers.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.scgl.suppliers.domain.SuppliersManage;
import com.scgl.suppliers.service.ISuppliersManageService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 管理Controller
 *
 * @author mobai
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/manage")
public class SuppliersManageController extends BaseController
{
    @Autowired
    private ISuppliersManageService suppliersManageService;

    /**
     * 查询管理列表
     */
    @RequiresPermissions("suppliers:manage:list")
    @GetMapping("/list")
    public TableDataInfo list(SuppliersManage suppliersManage)
    {
        startPage();
        List<SuppliersManage> list = suppliersManageService.selectSuppliersManageList(suppliersManage);
        return getDataTable(list);
    }

    /**
     * 导出管理列表
     */
    @RequiresPermissions("suppliers:manage:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SuppliersManage suppliersManage)
    {
        List<SuppliersManage> list = suppliersManageService.selectSuppliersManageList(suppliersManage);
        ExcelUtil<SuppliersManage> util = new ExcelUtil<SuppliersManage>(SuppliersManage.class);
        util.exportExcel(response, list, "管理数据");
    }

    /**
     * 获取管理详细信息
     */
    @RequiresPermissions("suppliers:manage:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(suppliersManageService.selectSuppliersManageById(id));
    }

    /**
     * 新增管理
     */
    @RequiresPermissions("suppliers:manage:add")
    @PostMapping
    public AjaxResult add(@RequestBody SuppliersManage suppliersManage)
    {
        suppliersManage.setCreateDate(new Date());
        return toAjax(suppliersManageService.insertSuppliersManage(suppliersManage));
    }

    /**
     * 修改管理
     */
    @RequiresPermissions("suppliers:manage:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody SuppliersManage suppliersManage)
    {
        return toAjax(suppliersManageService.updateSuppliersManage(suppliersManage));
    }

    /**
     * 删除管理
     */
    @RequiresPermissions("suppliers:manage:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(suppliersManageService.deleteSuppliersManageByIds(ids));
    }
}
